
#include "./queue-impl.h"

namespace fasmio { namespace container {

QueueImpl::QueueImpl() :
    task_queue_()
{
}

QueueImpl::~QueueImpl()
{
}

service::ITask* QueueImpl::GetTask()
{
    return GetTask(true, 0xFFFFFFFF);
}

service::ITask* QueueImpl::GetTask(bool blocking, unsigned timeout)
{
    service::ITask* task = task_queue_.Pop(blocking, timeout);
    if (task != nullptr)
        OnPostGetTask(task);
    return task;
}

unsigned long QueueImpl::GetTasks(service::ITask* tasks[], unsigned long count)
{
    return GetTasks(tasks, count, true, 0xFFFFFFFF);
}

unsigned long QueueImpl::GetTasks(service::ITask* tasks[], unsigned long count, bool blocking, unsigned timeout)
{
    // TODO: QueueImpl::GetTasks
    return 0;
}

void QueueImpl::TaskDone()
{
    TaskDone(1);
}

void QueueImpl::TaskDone(unsigned long count)
{
    OnTaskDone(count);
    task_queue_.TaskDone(count);
}

bool QueueImpl::AddTask(service::ITask* task)
{
    if (task == nullptr)
        return false;

    OnAnteAddTask(task);
    task_queue_.Push(task);
    return true;
}

bool QueueImpl::SetFilter(service::TaskFilter filter)
{
    // TODO: QueueImpl::SetFilter
    return false;
}

unsigned long QueueImpl::GetSize()
{
    return task_queue_.Size();
}

unsigned long QueueImpl::GetTraffic()
{
    // TODO: QueueImpl::GetTraffic
    return 0;
}

}}  // namespace fasmio::container
